<template>
	<view class="brand-images">
		<block v-if="show">
			<view class="brand-images-tabs">
				<u-tabs
					:list="brandImagesTabsList"
					:current="brandImagesIndex"
					@change="brandImagesTabsChange"
					inactive-color="#666"
					active-color="#141414"
					font-size="28"
					name="class_name"
					bg-color="#FFF"></u-tabs>
			</view>
			<view class="brand-images-list">
				<view class="brand-images-item" v-for="(data,index) in list" :key="index">
					<image :src="data.image" mode="widthFix" @click="previewImgs(data.image)"></image>
					<view class="brand-images-name" v-if="data.fabric_sn">{{data.fabric_sn}}</view>
				</view>
			</view>
			<pt-loading-more v-if="isLoading"></pt-loading-more>
			<pt-nomore v-if="noMore && list.length"></pt-nomore>
			<pt-nothing 
				text="暂无面料" 
				:fixed="true" 
				top="90"
				v-if="noMore && !list.length" 
				icon="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/nothing.png?v=1">
			</pt-nothing>
		</block>
		<pt-loading></pt-loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				factory_id: '',
				list: [],
				page: 0,
				isLoading: false,
				noMore: false,
				brandImagesTabsList: [],
				brandImagesIndex: 0,
				image_class_id: ''
			};
		},
		onLoad(options) {
			this.factory_id = options.factory_id
			this.init()
		},
		methods: {
			init(){
				this.$u.api.FactoryImage({factory_id: this.factory_id, type: 3,page: this.page,image_class_id: this.image_class_id}).then(res => {
					this.show = true
					this.isLoading = false
					this.brandImagesTabsList = res.datas.category_list
					this.brandImagesTabsList.unshift({
						class_name: '全部',
						class_id: ''
					})
					if(res.datas.data.length){
						res.datas.data.forEach(item => {
							this.list.push(item)
						})
					}else{
						this.noMore = true
					}
				})
			},
			previewImgs(current){
				let urls = []
				this.list.forEach(item => {
					urls.push(item.image)
				})
				uni.previewImage({
					current: current,
					urls: urls
				})
			},
			brandImagesTabsChange(e){
				this.brandImagesIndex = e
				this.image_class_id = this.brandImagesTabsList[e].class_id
				this.list = []
				this.page = 0
				this.noMore = false
				this.init()
			}
		},
		onReachBottom() {
			if(!this.noMore){
				this.page++
				this.isLoading = true
				this.init()
			}
		}
	}
</script>

<style lang="scss">
	.brand-images{
		padding-top: 80rpx;
		.brand-images-tabs{
			position: fixed;
			z-index: 10;
			left: 0;
			right: 0;
			top: 0;
		}
		.brand-images-list{
			padding: 1rpx 30rpx 30rpx;
			display: flex;
			align-items: flex-start;
			flex-wrap: wrap;
			justify-content: space-between;
			.brand-images-item{
				margin-top: 40rpx;
				width: 49%;
				image{
					width: 100%;
					border-radius: 8rpx 8rpx 0 0;
				}
				.brand-images-name{
					background-color: #F2F2F2;
					height: 110rpx;
					line-height: 110rpx;
					text-align: center;
					border-radius: 0 0 8rpx 8rpx;
					font-size: 32rpx;
					color: #141414;
					font-weight: bold;
				}
			}
		}
	}
</style>
